var router = require('koa-router')();

import cities from '../constants/cities';


router.post('/login',async (ctx, next)=>{
    var {account,password,code} = ctx.request.body;
    var result = await ctx.post('/web/login',{account,password});
    ctx.body = result;
});

router.post('/modify/password',async(ctx,next) =>{
	let{
		old_password,
		new_password,
		new_password_confirm,
	} = ctx.request.body;
	let result = await ctx.post('/web/change-password',{old_password,new_password,new_password_confirm});
	ctx.body = result;
})




// router.post('/send-code',async (ctx, next)=>{
//     var {name} = ctx.request.body;
//     console.log('/send-code================',name);
//     var result = await ctx.post('/user/login/sendCode',{name})
//     console.log('/send-code================',result);
//     // console.log("-------验证码为--------",result);
//     // if(process.env.NODE_ENV=="dev"&&result.cd==0){
//          result.code = result.data.code;
//     // }
// console.log(result , "----res")
//     ctx.body = result;
// });

// router.post('/modify/password',async(ctx,next) => {
//     let {passwd} = ctx.request.body;
//     console.log('/modify/password---',passwd);
//     let result = await ctx.post('/user/login/chpwd',{passwd})
//     console.log('/modify/password---result',result);
//     ctx.body = result;
// })

//检查是否登录
router.post('/check/login',async (ctx,next) => {
	let result = await ctx.get('/web/info',{});
	console.log('/check/login==========',result);
	ctx.body = result;

	// let session = await ctx.sess();
	// let result = {
	// 	success:false,
	// 	message:"",
	// 	data:{},
	// 	ticket:"",
	// }
	// if (session.ticket && session.user) {
	// 	result.success = true;
	// 	result.data = session.user;
	// 	result.message = "Logined";
	// 	result.ticket = session.ticket;
	// }else{
	// 	result.success = false;
	// 	result.message = "User Unauthorized";
	// }
	// console.log('/check/login',result);
	
    // ctx.body = result;
})

//退出
router.post('/logout',async (ctx,next) => {
    ctx.clearSess();
    ctx.body = {success:true};
})





export default router;
